package com.pda.gongpin.ui.fullinventory;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.pda.gongpin.R;
import com.pda.gongpin.adapter.StockStatisticsAdapter;
import com.pda.gongpin.bean.StockStatisticsBean;
import com.pda.gongpin.contract.StockStatisticsContract;
import com.pda.gongpin.presenter.StockStatisticsPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class StockStatisticsFragment extends BaseMvpFragment<StockStatisticsPresenter> implements StockStatisticsContract.View, OnRefreshListener {
    @BindView(R.id.rv_content)
    RecyclerView rvList;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;

    private String entryNo;

    public StockStatisticsFragment(String entryNo) {
        this.entryNo = entryNo;
    }

    public StockStatisticsFragment() {
    }

    StockStatisticsAdapter adapter;

    @Override
    public StockStatisticsPresenter getPresenter() {
        return new StockStatisticsPresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        adapter = new StockStatisticsAdapter(R.layout.item_stock_statistics, new ArrayList<>(), entryNo);
        rvList.setLayoutManager(new LinearLayoutManager(mContext));
        rvList.setAdapter(adapter);
       smart.autoRefresh();
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }

    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.finishRefresh();
    }

    @Override
    public void setList(List<StockStatisticsBean> list) {
        adapter.setNewInstance(list);
        smart.finishRefresh();
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.countTaskstatisticsList(entryNo);
    }
}
